
Event.observe(window, 'load', function() {
    new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "productSearchServlet", {afterUpdateElement : getSelectionId});
});

function getSelectionId(text, li) {
    var myId = li.id;
    setTimeout(function(){
    new Ajax.Request('productValidateServlet', {
        method:'get',
        asynchronous: false,
        parameters: {id: myId},
        onSuccess: function(transport) {
            var response = transport.responseText.evalJSON();
            var item = response.item;
            var frm = 'quotationForm';
            
            $(frm + ':products:productPrice').value = item.price
            $(frm + ':products:productDescription').value = item.description;
            $(frm + ':products:productMeasure').value = item.measure;
            $(frm + ':products:productUnitMeasure').value = item.unitMeasure;
            $(frm + ':products:productId').value = myId;
        },
        onFailure: function() {
            alert('Fallo de conexion. Trate de nuevo');
        }
    });
    },0);

}